import urllib.request
import json


if __name__ == '__main__':
    ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 ' \
         'Safari/537.36 '
    req = urllib.request.Request('http://httpbin.org/user-agent')
    # 修改请求头-User-Agent
    req.add_header('User-Agent', ua)
    resp = urllib.request.urlopen(req)
    ret = json.load(resp)
    print('User-Agent: ', ret['user-agent'])



